<%@ page import="com.lk.bean.CartItem" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.lk.bean.Goods" %><%--
  @author  lk
  DateTime: 2020/4/14 0014 16:13
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>购物车结算页面</title>
</head>
<body>
<%
    Map<Integer, CartItem> map = (Map<Integer, CartItem>) session.getAttribute("cart");
    if (map != null) {
        for (Map.Entry<Integer, CartItem> entry : map.entrySet()) {

            Map<Goods, Integer> allMap = (Map<Goods, Integer>) request.getServletContext().getAttribute("allGoods");
            for (Map.Entry<Goods, Integer> entry2 : allMap.entrySet()) {
                if (entry2.getKey().getGoodsId().equals(entry.getValue().getGoods().getGoodsId())) {
                    entry2.setValue(entry2.getValue() + entry.getValue().getNumber());
                }
            }
            request.getServletContext().removeAttribute("allGoods");
            request.getServletContext().setAttribute("allGoods", allMap);
        }
        request.getSession().removeAttribute("cart");
    }
%>
<div style="text-align: center">
    <%
        if (map != null) {
            out.print("<h1>恭喜支付成功，静等商品送达</h1>");
        } else {
            out.print("<h1>您的购物车为空，暂时不用结算</h1>");
        }
    %>
    <h3><a href="index.jsp">返回首页</a></h3>
    <h3><a href="cart.jsp">回到购物车</a></h3>
</div>
</body>
</html>
